<?php

/*
 * Edit by shengxin
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
 */

namespace api\mall\task;

/**
 * Description of TaskChecker
 *
 * @author PC
 */
abstract class TaskChecker {
    protected $task_cfg;
    public $task_data = -1;
    
    public function __construct($cfg) {
        $this->task_cfg = $cfg;
    }


    public function check_comp($user): bool{
        if($this->task_data<0){
            $this->task_data = $this->queryTaskData($user);
        }
        return $this->check($this->task_data, $this->task_cfg);
    }
    
    /**
     * 检车任务是否完成
     */
    protected function check($task_data,$cfg):bool{
        return $task_data>=$cfg['task_req'];
    }
    /**
     * 查询任务数据
     */
    abstract protected function queryTaskData($user):int;
}
